//
//  PHStatusOriginalView.swift
//  PHWeibo
//
//  Created by 潘荟 on 16/7/23.
//  Copyright © 2016年 BAT. All rights reserved.
//

import UIKit

class PHStatusOriginalView: UIView {
    
    var statusViewModel:PHStatusViewModel?{
        didSet{
            headImageView.ph_setImage(statusViewModel?.status?.user?.profile_image_url, placeholderImageName: "avatar_default")
            
            nameLabel.text = statusViewModel?.status?.user?.name
            
            avatarImageView.image = statusViewModel?.avatarImage
            memberImageView.image = statusViewModel?.memberImage
            
            timeLabel.text = "时间"
            sourceLabel.text = "来自东海"
            contentLabel.text = "海贼王海贼王海贼王海贼王海贼王海贼王海贼王海贼王海贼王海贼王海贼王海贼王海贼王海贼王海贼王海贼王海贼王海贼王"
            
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置界面
    func setupUI() {
//        self.backgroundColor = RandomColor()
        
        //添加子控件
        addSubview(headImageView)
        addSubview(nameLabel)
        addSubview(memberImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(avatarImageView)
        addSubview(contentLabel)
        
        
        //设置约束
        headImageView.snp_makeConstraints { (make) -> Void in
            make.leading.top.equalTo(10)
            make.size.equalTo(CGSize(width: 35, height: 35))

        }
        
        // 02
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImageView)
            make.leading.equalTo(headImageView.snp_trailing).offset(10)
        }
        // 03
        memberImageView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(nameLabel.snp_trailing).offset(10)
            make.centerY.equalTo(nameLabel)
        }
        // 04
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(nameLabel)
            make.bottom.equalTo(headImageView)
        }
        // 05
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(timeLabel.snp_trailing).offset(10)
            make.bottom.equalTo(timeLabel)
        }
        // 06
        avatarImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImageView.snp_trailing)
            make.centerY.equalTo(headImageView.snp_bottom)
        }
        
        // 07
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImageView.snp_bottom).offset(10)
            make.leading.equalTo(headImageView)
        }
        
        //给当前view设置约束
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(contentLabel).offset(10)
        }
    }
    
    // MARK: - 懒加载子控件
    //头像
    private lazy var headImageView:UIImageView = UIImageView(imgName: "avatar_default")
    
    // 昵称
    private lazy var nameLabel: UILabel = UILabel(textColor: UIColor.blackColor(), textFont: 15)
    // 微博等级common_icon_membership
    private lazy var memberImageView: UIImageView = UIImageView(imgName: "common_icon_membership")
    // 微博时间
    private lazy var timeLabel: UILabel = UILabel(textColor: themeColor, textFont: 10)
    // 微博来源
    private lazy var sourceLabel: UILabel = UILabel(textColor: themeColor, textFont: 10)
    // 认证logo avatar_vgirl
    private lazy var avatarImageView: UIImageView = UIImageView(imgName: "avatar_vgirl")
    
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 15, maxWidth: SCREENW - 20)
}





